package cn.pugle.base.innerclass;

/**
 * Created by tzp on 15-11-5.<br/>
 */
public class NestedClassTest {
    private String outerClassPrivField = "I'm outerClassPrivField";
    String outerClassDefaField = "I'm outerClassDefaField";

    class NonStaticInnerClass {
        //        static String innerField = ""; //xxx error , 非静态内部类不能有静态域
        //xxx 但是非静态内部类包有外部类的对象，可以直接访问外部对象的任意域
        String getOuterDefaField() {
            return outerClassDefaField;
        }

        String getOuterPrivField() {
            return outerClassPrivField;
        }
    }

    static class StaticInnerClass {
        static String innerField = "inner field";
        /*String getOuterDefaField() {
            return outerClassDefaField;
        }*/ //xxx 没有这功能，static inner 和外部类没啥交互

    }

    public static void main(String[] args) {
        NestedClassTest nestedClassTest = new NestedClassTest();
        NonStaticInnerClass nonStaticInnerClass = nestedClassTest.new NonStaticInnerClass();
        StaticInnerClass staticInnerClass = new StaticInnerClass();
        System.out.println(nonStaticInnerClass.getOuterPrivField());
    }
}
